module dice.ui.theme;

import dice.ui.gadget;
import dice.ui.container;
import dice.render.painter;

import std.stdio;

/** Something responsible for drawing widgets */
abstract class Theme
{
	void traceRect (Gadget g, Painter p, float w)
	{
		p.move(w/2, w/2);
		p.line(g.rect.x2-g.rect.x1-w/2, w/2);
		p.line(g.rect.x2-g.rect.x1-w/2, g.rect.y2-g.rect.y1-w/2);
		p.line(w/2, g.rect.y2-g.rect.y1-w/2);
		p.close();
	}
	
	abstract void delegate (Gadget, Painter) drawDelegateFor (Gadget g);
} 

/** The default theme */
class DefaultTheme : Theme
{
	void drawUnknownGadget (Gadget g, Painter p)
	{
		//writefln("drawUnknownGadget(%s,%s)", cast(void*) g, cast(void*) p);
		traceRect(g,p,2);
		p.colour = Colour(1,0,0,0.5);
		p.fillPreserve();
		p.colour = Colour(0,0,0,1);
		p.width = 2;
		p.stroke();
	}
	
	void drawContainer (Gadget _g, Painter p)
	{
		Container c = cast(Container)_g;
		drawUnknownGadget(c,p);
		c.drawContents(p);
	}
	
	void delegate (Gadget, Painter) drawDelegateFor (Gadget g)
	{
		if (cast(Container)g !is null)
			return &drawContainer; 
		return &drawUnknownGadget;
	}
}
